﻿CREATE PROCEDURE [dbo].[WorkTime_Create]
	@TaskId int,
	@UserAccountId int,
	@StartTime datetime,
	@EndTime datetime,
	@Note nvarchar(255)
AS
BEGIN
	declare @TotalSeconds int

	if @EndTime is not null
		set @TotalSeconds = DATEDIFF(second, @StartTime, @EndTime)
	
	if (@TotalSeconds > 0 or @TotalSeconds is null)
	begin
		insert into WorkTime (TaskId, UserAccountId, StartTime, EndTime, TotalSeconds, Note) values (@TaskId, @UserAccountId, @StartTime, @EndTime, @TotalSeconds, @Note)
		select SCOPE_IDENTITY()
	end
END